﻿Imports System.Xml
Imports System.Text
Imports ibnCredentials.FtpCreds

Public Class Form2

    Private Sub txtboxPassword_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtboxPassword.KeyUp
        If e.KeyCode = Keys.Enter Then
            btnSavePass.PerformClick()
        End If
    End Sub

    Private Sub txtboxPassword_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtboxPassword.TextChanged
        If txtboxPassword.Text.GetHashCode.ToString().ToString = Password.GetHashCode.ToString().ToString Then 'if password is correct, show notice and enable the save button
            btnSavePass.Enabled = True
            lblPassCorrect.Visible = True
        End If
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.FormBorderStyle = FormBorderStyle.FixedSingle
        btnSavePass.Enabled = False
        lblPassCorrect.Visible = False
        Me.Focus.Equals(True)
        txtboxPassword.Focus()
    End Sub

    Private Sub btnSavePass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSavePass.Click
        Dim passHash As String
        passHash = Password
        Dim sb As New StringBuilder 'create the xml, write and save the password to it
        sb.Append("<Check><AppPass>" & passHash.GetHashCode.ToString().ToString & "</AppPass></Check>")
        Dim doc As New XmlDocument
        doc.LoadXml(sb.ToString)
        doc.Save(Form1.settingsFile)
        Form1.btnGetList.Enabled = True 'enable the actor list button once password is correctly entered and saved
        Me.Close()
    End Sub
End Class